<?php

namespace App\Http\Requests\UserApi;

use App\Http\Requests\BaseRequest;
use Illuminate\Foundation\Http\FormRequest;

class IntegralPlanRequest extends BaseRequest
{
    protected $rules = [

    ];

    //这里我只写了部分字段，可以定义全部字段
    protected $strings_key = [
        'integral_plan_id' => '方案ID',
        'pay_type_id' => '支付類型ID',
        'proof_img' => '圖片',
    ];

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $function = request()->route()->getAction();
        $rules = $this->rules;

        // 根据不同的情况, 添加不同的验证规则
        if ($function['controller'] == 'App\Http\Controllers\UserApi\IntegralPlanController@intgral_plan_info')
        {
            $rules=[
                'integral_plan_id'=>'required|exists:integral_plan,id',
            ];
        }

        if ($function['controller'] == 'App\Http\Controllers\UserApi\UserIntegralController@apply_integral')
        {
            $rules=[
                'integral_plan_id'=>'required|exists:integral_plan,id',
                'pay_type_id'=>'required|exists:pay_type,id',
                'proof_img'=>'required',
            ];
        }

        return $rules;
    }
}
